<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><%@ 
	taglib prefix="s" uri="/struts-tags"%><%@ 
	include file="/taglibs.jsp"%>
<%@ page import="com.yaodian100.core.common.utils.ServerValue"%>
<c-rt:set var="midContextPath" value='<%=ServerValue.getMidContextPath()%>' />
<script src="${midContextPath}/js/jquery.form.js"></script>
<script>
	$().ready( function() {
		$("#roletypeParam").change(function(){
			var roleType = $(this).val();
			getRoles(roleType);
		});
		getRoles('${roletypeParam}');
		function getRoles(roleType) {
			if (roleType != "") {
				$("#formObj").ajaxSubmit({
				    url: '${midContextPath}/account/listRoles.do',
				    cache: false,
				    type: 'post',
				    success: function(jsonRoles){
				    	initRolesInput(jsonRoles);
					}
				});
			} else {
				$("#roleParam").empty();
				$("#roleParam").append("<option value=''>全部</option>");
			}
		}
		
		function initRolesInput(jsonRoles) {
			eval("var roles = " + jsonRoles + ";");
			$("#roleParam").empty();
			$("#roleParam").append("<option value=''>全部</option>");
			for (var i=0;i<roles.length;i++) {
				if (roles[i].type == "MANAGER") {
					$("#roleParam").append("<option value='" + roles[i].key + "'>" + roles[i].keyDesc + "</option>");
				} else {
					$("#roleParam").append("<option value='" + roles[i].key + "'>" + roles[i].description + "</option>");
				}
			}

			var role = '${roleParam}';
			if (role != "") {
				$("#roleParam").val(role);
			}
			
		}
	});
</script>
<div style="color:red">
<s:actionerror/>
<s:actionmessage/>
<s:fielderror />
</div>
<BR>
<h1>使用者管理
	<div class="f-link">
		<a href="add.do">新增</a>
		<a href="#" onclick="document.formObj.submit();">搜寻</a>
	</div>
</h1>
<s:form action="search.do" method="post" id="formObj">
<div class="data-form">
		<b>登入代码：</b>
		<input name="usernameParam" id="usernameParam" type="text" value="${usernameParam}">
		<b>电子邮件：</b>
		<input name="emailParam" id="emailParam" type="text" value="${emailParam}"><br/>
		<b>部门：</b>
		<!-- <input name="groupParam" id="groupParam" type="text" value="${groupParam}">-->
		<s:select list="groups" name="groupParam" listKey="code" listValue="description" headerKey="" headerValue="全部"></s:select>
		<b>狀態：</b>
		<s:checkboxlist list="userStatus.options" name="statusParam" listKey="value.code" listValue="value.name"/>
		<br/>
		<b>角色类型</b>
		<s:select list="roleTypes" name="roletypeParam" id="roletypeParam" listKey="key.code" listValue="value" headerKey="" headerValue="全部"></s:select>
		<b>角色</b>
		<select id="roleParam" name="roleParam"></select>
	</div>
		</s:form>
<br/><br/><br/>
<s:if test="users.size > 0">
	<yaodian100:pageutil pagerObj="${pager}" link="search.do"/>
  <table class="tb-1" width="800">
		<thead>
			<tr>
				<th>#</th>
				<th>登入代码</th>
				<th>姓名</th>
				<th>电子邮件</th>
				<th>部门</th>
				<th>狀態</th>
			</tr>
		</thead>
		<tbody>
			<c:forEach items="${users}" var="user" varStatus="rows_index">
				<tr class="${rows_index.count % 2 == 0 ? 'bg-yl' : ''}">
					<td>${rows_index.count + pager.currentPage*20}</td>
					<td><a href="view.do?username=${user.username}"/>${user.username}</a></td>
					<td>${user.nameNative}</td>
					<td>${user.email}</td>
					<td>${user.group.code}/${user.group.description}</td>
					<td>${userStatus.options[user.status].name}</td>
				</tr>
			</c:forEach>
		</tbody>
	</table>
	<yaodian100:pageutil pagerObj="${pager}" link="search.do"/>
</s:if>
